package cn.edu.neusoft.demo.hospital2.Controller;

import cn.edu.neusoft.demo.hospital2.Service.MessageboardService;
import cn.edu.neusoft.demo.hospital2.pojo.Messageboard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/messageboard")
public class MessageboardController {
    @Autowired
    private MessageboardService messageboardService;

    @GetMapping("/all")
    public List<Messageboard> getAllMessages() {
        return messageboardService.getMessageList();
    }

    @GetMapping("/message/{userId}")
    public List<Messageboard> getMessageById(@PathVariable Integer userId) {
        return messageboardService.getMessageById(userId); // 返回列表
    }


    @PostMapping("/add")
    public int addMessage(@RequestBody Messageboard messageboard) {
        return messageboardService.addMessage(messageboard);
    }

    @PutMapping("/update")
    public int updateMessage(@RequestBody Messageboard messageboard) {
        return messageboardService.updateMessage(messageboard);
    }

    @DeleteMapping("/delete/{userId}")
    public int deleteMessage(@PathVariable Integer userId) {
        return messageboardService.deleteMessageById(userId);
    }
}
